lib/pull: Avoid journaling 404s for optional content
authorColin Walters <walters@verbum.org>
Wed, 5 Jul 2017 20:41:38 +0000 (16:41 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Thu, 13 Jul 2017 21:41:00 +0000 (21:41 +0000)
Currently in Fedora we don't sign summaries, and every use of
`rpm-ostree` would emit to the journal an error when we failed
to fetch it.

Fix this by having `OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT` tell the fetcher
not to journal 404 errors. While fixing this, we had a mix of two booleans vs
the flags; fix things so we consistently use the flags in the fetcher and pull
code.

Closes: #1004
Approved by: mbarnes

src/libostree/ostree-fetcher-curl.c
src/libostree/ostree-fetcher-soup.c
src/libostree/ostree-fetcher-util.c
src/libostree/ostree-fetcher-util.h
src/libostree/ostree-fetcher.h
src/libostree/ostree-metalink.c
src/libostree/ostree-repo-pull.c

index 77844ec7ace56fa8a2cf9397cb501caac439268f..ae8bea73ae43c4b36bc72980a8c031b287b2d221 100644 (file)
@@ -353,7 +353,9 @@ check_multi_info (OstreeFetcher *fetcher)
                   g_autofree char *msg = g_strdup_printf ("Server returned HTTP %lu", response);
                   g_task_return_new_error (task, G_IO_ERROR, giocode,
                                            "%s", msg);
-                  if (req->fetcher->remote_name)
+                  if (req->fetcher->remote_name &&
+                      !((req->flags & OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT) > 0 &&
+                        giocode == G_IO_ERROR_NOT_FOUND))
                     _ostree_fetcher_journal_failure (req->fetcher->remote_name,
                                                      eff_url, msg);
 
@@ -859,13 +861,14 @@ void
 _ostree_fetcher_request_to_tmpfile (OstreeFetcher         *self,
                                     GPtrArray             *mirrorlist,
                                     const char            *filename,
+                                    OstreeFetcherRequestFlags flags,
                                     guint64                max_size,
                                     int                    priority,
                                     GCancellable          *cancellable,
                                     GAsyncReadyCallback    callback,
                                     gpointer               user_data)
 {
-  _ostree_fetcher_request_async (self, mirrorlist, filename, 0, FALSE,
+  _ostree_fetcher_request_async (self, mirrorlist, filename, flags, FALSE,
                                  max_size, priority, cancellable,
                                  callback, user_data);
 }
index b877d27c383212532b3136359b2f75669236f919..16fda0a31b3e66ca0429aa61e38b504dff003c28 100644 (file)
@@ -1128,7 +1128,9 @@ on_request_sent (GObject        *object,
                 g_prefix_error (&local_error,
                                 "All %u mirrors failed. Last error was: ",
                                 pending->mirrorlist->len);
-              if (pending->thread_closure->remote_name)
+              if (pending->thread_closure->remote_name &&
+                  !((pending->flags & OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT) > 0 &&
+                    code == G_IO_ERROR_NOT_FOUND))
                 _ostree_fetcher_journal_failure (pending->thread_closure->remote_name,
                                                  uristring, local_error->message);
 
@@ -1238,13 +1240,14 @@ void
 _ostree_fetcher_request_to_tmpfile (OstreeFetcher         *self,
                                     GPtrArray             *mirrorlist,
                                     const char            *filename,
+                                    OstreeFetcherRequestFlags flags,
                                     guint64                max_size,
                                     int                    priority,
                                     GCancellable          *cancellable,
                                     GAsyncReadyCallback    callback,
                                     gpointer               user_data)
 {
-  _ostree_fetcher_request_async (self, mirrorlist, filename, 0, FALSE,
+  _ostree_fetcher_request_async (self, mirrorlist, filename, flags, FALSE,
                                  max_size, priority, cancellable,
                                  callback, user_data);
 }
index 408b8bcb4eb2594147a1939400ef268e09b479cc..7a6d94cc3389a5adb53e2ad944875b33feafbff2 100644 (file)
@@ -55,8 +55,7 @@ gboolean
 _ostree_fetcher_mirrored_request_to_membuf (OstreeFetcher  *fetcher,
                                             GPtrArray     *mirrorlist,
                                             const char     *filename,
-                                            gboolean        add_nul,
-                                            gboolean        allow_noent,
+                                            OstreeFetcherRequestFlags flags,
                                             GBytes         **out_contents,
                                             guint64        max_size,
                                             GCancellable   *cancellable,
@@ -79,7 +78,7 @@ _ostree_fetcher_mirrored_request_to_membuf (OstreeFetcher  *fetcher,
   data.error = error;
 
   _ostree_fetcher_request_to_membuf (fetcher, mirrorlist, filename,
-                                     add_nul ? OSTREE_FETCHER_REQUEST_NUL_TERMINATION : 0,
+                                     flags,
                                      max_size, OSTREE_FETCHER_DEFAULT_PRIORITY,
                                      cancellable, fetch_uri_sync_on_complete, &data);
   while (!data.done)
@@ -87,7 +86,7 @@ _ostree_fetcher_mirrored_request_to_membuf (OstreeFetcher  *fetcher,
 
   if (!data.result_buf)
     {
-      if (allow_noent)
+      if (flags & OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT)
         {
           if (g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
             {
@@ -112,8 +111,7 @@ _ostree_fetcher_mirrored_request_to_membuf (OstreeFetcher  *fetcher,
 gboolean
 _ostree_fetcher_request_uri_to_membuf (OstreeFetcher  *fetcher,
                                        OstreeFetcherURI *uri,
-                                       gboolean        add_nul,
-                                       gboolean        allow_noent,
+                                       OstreeFetcherRequestFlags flags,
                                        GBytes         **out_contents,
                                        guint64        max_size,
                                        GCancellable   *cancellable,
@@ -121,8 +119,7 @@ _ostree_fetcher_request_uri_to_membuf (OstreeFetcher  *fetcher,
 {
   g_autoptr(GPtrArray) mirrorlist = g_ptr_array_new ();
   g_ptr_array_add (mirrorlist, uri); /* no transfer */
-  return _ostree_fetcher_mirrored_request_to_membuf (fetcher, mirrorlist, NULL,
-                                                     add_nul, allow_noent,
+  return _ostree_fetcher_mirrored_request_to_membuf (fetcher, mirrorlist, NULL, flags,
                                                      out_contents, max_size,
                                                      cancellable, error);
 }
index fe0921cd46f72991ff05016b02b507c43598d245..c099a87241b750a875364427080d96d46897b996 100644 (file)
@@ -29,8 +29,7 @@ G_BEGIN_DECLS
 gboolean _ostree_fetcher_mirrored_request_to_membuf (OstreeFetcher *fetcher,
                                                      GPtrArray     *mirrorlist,
                                                      const char    *filename,
-                                                     gboolean       add_nul,
-                                                     gboolean       allow_noent,
+                                                     OstreeFetcherRequestFlags flags,
                                                      GBytes         **out_contents,
                                                      guint64        max_size,
                                                      GCancellable   *cancellable,
@@ -38,8 +37,7 @@ gboolean _ostree_fetcher_mirrored_request_to_membuf (OstreeFetcher *fetcher,
 
 gboolean _ostree_fetcher_request_uri_to_membuf (OstreeFetcher *fetcher,
                                                 OstreeFetcherURI *uri,
-                                                gboolean       add_nul,
-                                                gboolean       allow_noent,
+                                                OstreeFetcherRequestFlags flags,
                                                 GBytes         **out_contents,
                                                 guint64        max_size,
                                                 GCancellable   *cancellable,
index 8ec5f209ad79f417568ff6f93b3364345b61a47a..2dbace7853265170a6b28360b76a878924a0c92b 100644 (file)
@@ -54,6 +54,11 @@ typedef enum {
   OSTREE_FETCHER_FLAGS_TRANSFER_GZIP = (1 << 1)
 } OstreeFetcherConfigFlags;
 
+typedef enum {
+  OSTREE_FETCHER_REQUEST_NUL_TERMINATION = (1 << 0),
+  OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT = (1 << 1)
+} OstreeFetcherRequestFlags;
+
 void
 _ostree_fetcher_uri_free (OstreeFetcherURI *uri);
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(OstreeFetcherURI, _ostree_fetcher_uri_free)
@@ -111,6 +116,7 @@ guint64 _ostree_fetcher_bytes_transferred (OstreeFetcher       *self);
 void _ostree_fetcher_request_to_tmpfile (OstreeFetcher         *self,
                                          GPtrArray             *mirrorlist,
                                          const char            *filename,
+                                         OstreeFetcherRequestFlags flags,
                                          guint64                max_size,
                                          int                    priority,
                                          GCancellable          *cancellable,
@@ -122,10 +128,6 @@ gboolean _ostree_fetcher_request_to_tmpfile_finish (OstreeFetcher *self,
                                                     char         **out_filename,
                                                     GError       **error);
 
-typedef enum {
-  OSTREE_FETCHER_REQUEST_NUL_TERMINATION = (1 << 0)
-} OstreeFetcherRequestFlags;
-
 void _ostree_fetcher_request_to_membuf (OstreeFetcher         *self,
                                         GPtrArray             *mirrorlist,
                                         const char            *filename,
index 6afae59e771a14efd258c8b1229917c148df1770..0b1b14fb933463fb50a664f0326c4a68d23bde13 100644 (file)
@@ -431,10 +431,7 @@ try_one_url (OstreeMetalinkRequest *self,
   gssize n_bytes;
 
   if (!_ostree_fetcher_request_uri_to_membuf (self->metalink->fetcher,
-                                              uri,
-                                              FALSE,
-                                              FALSE,
-                                              &bytes,
+                                              uri, 0, &bytes,
                                               self->metalink->max_size,
                                               self->cancellable,
                                               error))
@@ -614,14 +611,9 @@ _ostree_metalink_request_sync (OstreeMetalink        *self,
   request.urls = g_ptr_array_new_with_free_func ((GDestroyNotify) _ostree_fetcher_uri_free);
   request.parser = g_markup_parse_context_new (&metalink_parser, G_MARKUP_PREFIX_ERROR_POSITION, &request, NULL);
 
-  if (!_ostree_fetcher_request_uri_to_membuf (self->fetcher,
-                                              self->uri,
-                                              FALSE,
-                                              FALSE,
-                                              &contents,
-                                              self->max_size,
-                                              cancellable,
-                                              error))
+  if (!_ostree_fetcher_request_uri_to_membuf (self->fetcher, self->uri, 0,
+                                              &contents, self->max_size,
+                                              cancellable, error))
     goto out;
 
   data = g_bytes_get_data (contents, &len);
index 5e0ae6ec6894d9d2a23b37f9f37001e9868d3d4e..34ea7f9edd3ee95d03c8f9eb00ae5065eeec5381 100644 (file)
@@ -470,7 +470,7 @@ fetch_mirrored_uri_contents_utf8_sync (OstreeFetcher  *fetcher,
 {
   g_autoptr(GBytes) bytes = NULL;
   if (!_ostree_fetcher_mirrored_request_to_membuf (fetcher, mirrorlist,
-                                                   filename, TRUE, FALSE,
+                                                   filename, OSTREE_FETCHER_REQUEST_NUL_TERMINATION,
                                                    &bytes,
                                                    OSTREE_MAX_METADATA_SIZE,
                                                    cancellable, error))
@@ -1864,6 +1864,7 @@ start_fetch (OtPullData *pull_data,
   else
     pull_data->n_outstanding_content_fetches++;
 
+  OstreeFetcherRequestFlags flags = 0;
   /* Override the path if we're trying to fetch the .commitmeta file first */
   if (fetch->is_detached_meta)
     {
@@ -1871,6 +1872,7 @@ start_fetch (OtPullData *pull_data,
       _ostree_loose_path (buf, expected_checksum, OSTREE_OBJECT_TYPE_COMMIT_META, pull_data->remote_mode);
       obj_subpath = g_build_filename ("objects", buf, NULL);
       mirrorlist = pull_data->meta_mirrorlist;
+      flags |= OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT;
     }
   else
     {
@@ -1890,7 +1892,7 @@ start_fetch (OtPullData *pull_data,
     expected_max_size = 0;
 
   _ostree_fetcher_request_to_tmpfile (pull_data->fetcher, mirrorlist,
-                                      obj_subpath, expected_max_size,
+                                      obj_subpath, flags, expected_max_size,
                                       is_meta ? OSTREE_REPO_PULL_METADATA_PRIORITY
                                       : OSTREE_REPO_PULL_CONTENT_PRIORITY,
                                       pull_data->cancellable,
@@ -1995,7 +1997,7 @@ start_fetch_deltapart (OtPullData *pull_data,
   g_assert_cmpint (pull_data->n_outstanding_deltapart_fetches, <=, _OSTREE_MAX_OUTSTANDING_DELTAPART_REQUESTS);
   _ostree_fetcher_request_to_tmpfile (pull_data->fetcher,
                                       pull_data->content_mirrorlist,
-                                      deltapart_path, fetch->size,
+                                      deltapart_path, 0, fetch->size,
                                       OSTREE_FETCHER_DEFAULT_PRIORITY,
                                       pull_data->cancellable,
                                       static_deltapart_fetch_on_complete,
@@ -2677,7 +2679,8 @@ _ostree_preload_metadata_file (OstreeRepo    *self,
   else
     {
       ret = _ostree_fetcher_mirrored_request_to_membuf (fetcher, mirrorlist,
-                                                        filename, FALSE, TRUE,
+                                                        filename,
+                                                        OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT,
                                                         out_bytes,
                                                         OSTREE_MAX_METADATA_SIZE,
                                                         cancellable, error);
@@ -3514,7 +3517,7 @@ ostree_repo_pull_with_options (OstreeRepo             *self,
       {
         if (!_ostree_fetcher_mirrored_request_to_membuf (pull_data->fetcher,
                                                          pull_data->meta_mirrorlist,
-                                                         "summary.sig", FALSE, TRUE,
+                                                         "summary.sig", OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT,
                                                          &bytes_sig,
                                                          OSTREE_MAX_METADATA_SIZE,
                                                          cancellable, error))
@@ -3538,7 +3541,7 @@ ostree_repo_pull_with_options (OstreeRepo             *self,
       {
         if (!_ostree_fetcher_mirrored_request_to_membuf (pull_data->fetcher,
                                                          pull_data->meta_mirrorlist,
-                                                         "summary", FALSE, TRUE,
+                                                         "summary", OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT,
                                                          &bytes_summary,
                                                          OSTREE_MAX_METADATA_SIZE,
                                                          cancellable, error))
@@ -4776,8 +4779,7 @@ find_remotes_cb (GObject      *obj,
               if (!_ostree_fetcher_mirrored_request_to_membuf (fetcher,
                                                                mirrorlist,
                                                                commit_filename,
-                                                               FALSE,  /* don’t add trailing nul */
-                                                               TRUE,  /* return NULL on ENOENT */
+                                                               OSTREE_FETCHER_REQUEST_OPTIONAL_CONTENT,
                                                                &commit_bytes,
                                                                0,  /* no maximum size */
                                                                cancellable,